package com.aimosheng.main.custom.videoplayerrecyclerview;

import android.content.Context;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import android.util.AttributeSet;


public class VideoPlayRecyclerView extends RecyclerView {

    private RecyclerView recyclerView;
    private PagerLayoutManager layoutManager;

    public VideoPlayRecyclerView(Context context) {
        super(context);
        this.init();
    }

    public VideoPlayRecyclerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.init();
    }

    public VideoPlayRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.init();
    }

    private void init() {
        this.recyclerView = this;
        this.layoutManager = new PagerLayoutManager(this.getContext());
        this.recyclerView.setLayoutManager(this.layoutManager);
    }

    public RecyclerView getRecyclerView() {
        return this.recyclerView;
    }

    public void setAdapter(VideoPlayAdapter adapter) {
        this.recyclerView.setAdapter(adapter);
        this.layoutManager.setOnPageChangeListener(adapter);
    }

    public void scrollToPosition(int position) {
        this.layoutManager.scrollToPositionWithOffset(position, 0);
    }
}
